classdef Tuner < Instrument

    properties
    
    end
    
    methods
    
        function this = Tuner(GPIB_controller, GPIB_address, address)
            this = this@Instrument(GPIB_controller, GPIB_address, address);
            this.reset();
            
        end
        function reset(this)
            cmd = sprintf('CLEAR\n');
            fprintf(this.conn,cmd);
            fscanf(this.conn);
            this.initTuner();
        end
        function initTuner(this)
            cmd = sprintf('INIT\n');
            fprintf(this.conn,cmd);
            this.waitForOPC();
        end
        
        function waitForOPC(this)
            cmd = sprintf('*OPC? 30\n');
            fprintf(this.conn,cmd);
            fscanf(this.conn);
        end
        
        function abort(this)
            cmd = sprintf('STOP\n');
            fprintf(this.conn,cmd);
        end
        
        function setMotorPosition(this, motor, position)
            cmd = sprintf('POS %d %d\n', motor, position);
            fprintf(this.conn,cmd);
        end
        
        function setReflectionCoefficient(this, gamma_r, gamma_theta)
            
            theta = theta*180/pi;
            cmd = sprintf('TUNE %.2f %.2f\n',gamma_r, gamma_theta);%%zmienic formatowanie stringa
            fprintf(this.conn,cmd);
        end
        
        function setVSWR(this,vswr)
            cmd = sprintf('TUNEVSWR %f\n',vswr);
            fprintf(this.conn,cmd);
        end
        
        function initConstantVSWR(this,vswr,option)
            %options: FWD,REV,OPT
            cmd = sprintf('VSWR:INIT %f %s\n',vswr,option);%
            fprintf(this.conn,cmd);
            this.waitForOPC();
        end
        
        function doFullCircleVSWR(this,speedFactor)
            cmd = sprintf('VSWR:DO360 %f\n',speedFactor);a
            fprintf(this.conn,cmd);
        end
        
        function performAutoVSWR(this,vswr,option)
            %options: FWD,REV,OPT
            cmd = sprintf('VSWR:AUTO %f %s\n',vswr,option);
            fprintf(this.conn,cmd);
        end
        
        function incrementConstantVSWRPhase(this, phase_step)
            cmd = sprintf('VSWR:STEP %d\n',phase_step);
            fprintf(this.conn,cmd);            
        end
        
        function getSParameters(this, harmonic_index)
            cmd = sprintf('SPAR? %u\n',harmonic_index);
            fprintf(this.conn,cmd);
            while length(result) == 0
                result = fscanf(this.connf);
            end
        end
        
        function parseSParametersString(this)
        end
        
        function loss = getLoss(this, harmonic_index)
        end
        
            
    end
    
end